<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <link rel="stylesheet" href="/src/css/base.css">
    <link rel="stylesheet/less" href="/src/css/xiaotao-ui.less">
    <script src="/src/js/ajax.js"></script>
    <script src="/src/js/base.js"></script>
    <script src="/src/dep/js/vue.js"></script>
    <script src="/src/js/xiaotao-ui.js"></script>
    <script src="/src/dep/js/less.min.js"></script>
    <style>
        #app{
            max-width: 400px;
            padding: 10px 30px 100px 30px;
        }
        h3{
            text-align: center;
        }
    </style>
</head>
<body>
    <form id="app" class="app">
        <h3>用户登录</h3>
        <div class="form-item">
            <xt-input placeholder="用户名" v-model="user" name="user"></xt-input>
        </div>
        <div class="form-item">
            <xt-input type="password" name="pwd" placeholder="密码" @keyup.enter.native="login" v-model="pwd"></xt-input>
        </div>
        <div class="form-item">
            <button type="button" @click="login">登录</button>
        </div>
    </form>
    <script>

        app = new Vue({
            el:"#app",
            data:{
                user:"",
                pwd:""
            },methods: {
                login() {
                    aoej.load()
                    $ajax("POST","/api/User/login",{pwd:this.pwd,user:this.user},(res)=>{
                        aoej.finish()
                        if(res.data.status == 1){
                            this.alert("提示","登录成功",{
                                callback:()=>{
                                    setTimeout(() => {
                                        var target = getQueryString("from")
                                        if ( target == '' ){
                                            target = '/'
                                        }
                                        location.href = target
                                    }, 500);
                                }
                            })
                        }else{
                            this.alert("提示","登录失败！原因：" + res.data.msg)
                        }
                    })
                },
            },
        })
            // app = document.getElementById("app")
            // function login(){
            //     aoej.load()
            //     $ajax("POST","/api/User/login",new FormData(app),(res)=>{
            //         aoej.finish()
            //         if(res.data.status == 1){
            //             $alert("提示","登录成功",()=>{
            //                 setTimeout(() => {
            //                     location.href = getQueryString("from")
            //                 }, 500);
            //             })
            //         }else{
            //             $alert("提示","登录失败！原因：" + res.data.msg,()=>{
            //                 document.getElementsByName("pwd")[0].focus()
            //             })
            //         }
            //     })
            //     return false
            // }
    </script>
</body>
</html>
